<template>
    <div>
        <home-header ></home-header>
        <home-swiper :list="swiperList"></home-swiper>
        <home-icons  :list="iconList"></home-icons>
        <home-recommend :list="recommendList"></home-recommend>
        <home-weekend :list="weekendList"></home-weekend>
    </div>
</template>

<script>
import HomeHeader from './component/Header'
import HomeSwiper from './component/Swiper'
import HomeIcons from './component/Icons'
import HomeRecommend from './component/Recommend'
import HomeWeekend from './component/Weekend'
import axios from 'axios'
import { mapState} from 'vuex'
export default {
  name: 'Home',
  data(){
    return {
      swiperList: [],
      iconList: [],
      recommendList: [],
      weekendList: [],
      lastCity: ''
    }
  },
  components: {
    HomeHeader: HomeHeader,
    HomeSwiper,
    HomeIcons,
    HomeRecommend,
    HomeWeekend
  },mounted () {
    //初始化赋值一样的值
    this.lastCity = this.city
    this.getHomeInfo()
  },methods: {
      getHomeInfo () {
        axios.
        // get("http://120.24.62.104/user/index")
        get('api/index.json?city=' +this.city )
        .then(this.getHomeInfoSuccess);
      },
      getHomeInfoSuccess (res) {
          res = res.data;
          console.log(res)
          if(res.ret && res.data){
              const data=res.data
              this.swiperList=data.swiperList;
              this.iconList= data.iconList
              this.recommendList= data.recommendList
              this.weekendList =data.weekendList
          }
      }
  },     
  computed: {
    ...mapState(['city'])
  },
  activated () {
    //判断是否更新城市
    if(this.lastCity !== this.city){
      //重新赋值
      this.lastCity =this.city
      //执行axios请求
      this.getHomeInfo()
    }

  }
}
</script>

<style>
</style>
